﻿using EPiAbstractions.Community.MyPage;
using EPiServer.Common.Security;
using EPiServer.Community.MyPage;
using JoelAbrahamsson.MetaWeblog;

namespace JoelAbrahamsson.BlogExtensions
{
    public class BlogProvider : IBlogProvider
    {
        public BlogProvider(IMyPageHandlerFacade myPageHandlerFacade)
        {
            MyPageHandlerFacade = myPageHandlerFacade;
        }

        public IMyPageHandlerFacade MyPageHandlerFacade { get; private set; }

        public BlogInfo[] GetUsersBlogs(IUser user)
        {
            MyPage myPage = MyPageHandlerFacade.GetMyPage(user);
            
            BlogInfo myPageBlogInfo = new BlogInfo
                                          {
                                              blogid = myPage.Blog.ID.ToString(),
                                              blogName = myPage.Blog.Name,
                                              url = "http://joelabrahamsson.com/"
                                          };

            return new [] { myPageBlogInfo };
        }
    }
}
